﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using Microsoft.Research.Kinect.Nui;
using Microsoft.Kinect;
using Kinect;

namespace KinectApplication
{
    public static class BlobParser
    {
        public static void ParseDepth(DepthImageFrame frame)
        {
            int arrayLength = frame.PixelDataLength;
            short[] depthArray = new short[arrayLength];
            frame.CopyPixelDataTo(depthArray);

            //var depthArray = frame.ToDepthArray();

            var blobs = depthArray.ExtractBlobs(640, 480, 800, 1000);

            if (blobs.Count > 0)
            {
                var blob = blobs.OrderByDescending(x => x.Area).First();

                List<Player> players = new List<Player>();

                Player player = new Player();

                if (blob.Area > 500 && blob.aspectRatio < 2.5)
                {
                    player.IsTracked = true;
                    player.Id = 666;
                    player.RightHand.IsTracked = true;
                }

              
                player.RightHand.X = blob.CenterOfGravity.X;
                player.RightHand.Y = blob.CenterOfGravity.Y;

                var handArray = depthArray.BlobArray(blob, 800, 1000);

#if DEBUG
                Debugging.ShowHand(handArray, (int)blob.Width, (int)blob.Height);
                Debugging.ShowBlobs(blobs);
#endif

                players.Add(player);

                MouseInput.Move(players);
            }


        }
    }
}
